/**
 * @author Yuqi Chou
 * @version  Aug 13, 2012
 */
package com.threeti.mecool.web.assembler;

import java.util.Map;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Path;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;

import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.domain.Specifications;

import com.threeti.mecool.core.domain.model.acl.PermissionRoleAchievement;

/**
 * @author Yuqi Chou
 * @version Aug 13, 2012 4:24:10 PM
 */
public abstract class PermissionRoleAchievementAssembler {
	
	public static Specification<PermissionRoleAchievement> toCriteria(Map<String,String> paramMap) {
		
		Specifications<PermissionRoleAchievement> spec = null;
		
		final Long jobId;
		try {
			jobId=Long.valueOf(paramMap.get("jobId"));
		} catch (Exception e) {
			return spec;
		}
		
		
		if(jobId!=null){
			spec=Specifications.where(new Specification<PermissionRoleAchievement>(){
				public Predicate toPredicate(Root<PermissionRoleAchievement> root,
											 CriteriaQuery<?> query,
											 CriteriaBuilder cb) {
					Path<String> userIdPath = root.get("job").get("id");
			        return cb.equal(userIdPath, jobId);
				}
			});
		}
		
		return spec;
	}
}



